var table;

$(function () {
    loadStoreList();
});

function loadStoreList() {
    var url = baseStoreUrl + "query/store";
    $.ajax({
        url: url,
        type: "GET",
        contentType: "application/json",
        success: function (data) {
            loadTable(data.data);
        }
    });
}

function loadTable(data) {
    $("#storeList").DataTable({
        data: data,
        searching: true,
        ordering: true,
        // ajax: {
        //     url: baseEquipmentUrl + "query/store",
        //     contentType: "application/json; charset=utf-8",
        //     type: "GET",
        //     data: function (req) {
        //         req.start = req.start;
        //         req.limit = req.length;
        //     },
        //     dataSrc: function (res) {
        //         res.recordsTotal = res.data.total;
        //         res.recordsFiltered = res.data.total;
        //         return res.data.rows;
        //     }
        // },
        // serverSide: true,
        select: true,
        columns: [
            {data: 'storeName'},
            {
                data: function (data, type, row, meta) {
                    if (isNull(data.head) && isNull(data.phone)) {
                        return "";
                    } else if (isNull(data.phone)) {
                        return data.head;
                    } else if (isNull(data.head)) {
                        return data.phone;
                    } else {
                        return data.head + "(" + data.phone + ")";
                    }
                }
            },
            {data: 'areaName'},
            {
                data: 'created',
                render: function (data, type, row, meta) {
                    return formatDate1(row.created);
                }
            },
            {data: 'num'}
        ],
        pagingType: "full_numbers",
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            oAria: {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
        columnDefs: [{
            targets: 5,
            render: function (data, type, row, meta) {
                return "<button type='button' style='margin-right: 10px;border: 1px solid #0D1113;color: #0D1113;background: transparent;' class='btn btn-primary' onclick='editEquipment(" + JSON.stringify(row) + ");'>编辑</button>";
            }
        }]
    });
}
